博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JSP-案例-商品增删改
阅读量:4350 次
发布时间:2019-06-07

本文共 4824 字,大约阅读时间需要 16 分钟。

商品的增删改查

1显示

 

部分代码

Dao

public List
findAllProduct() throws SQLException { QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource()); String sql = "select * from product"; List
productList = runner.query(sql, new BeanListHandler
(Product.class)); return productList; }

Jsp

${vs.count }
${pro.pname } ${pro.shop_price } ${pro.is_hot==1?"是":"否" }

 

2 增

先获得分类数据

//获得所有的商品的类别数据                  AdminProductService service = new AdminProductService();                  List
categoryList = null; try { categoryList = service.findAllCategory(); } catch (SQLException e) { e.printStackTrace(); } request.setAttribute("categoryList", categoryList);

 

在显示类别

 

 

接着做数据库添加操作

public void addProduct(Product product) throws SQLException {                  QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());                  String sql = "insert into product values(?,?,?,?,?,?,?,?,?,?)";                  runner.update(sql, product.getPid(),product.getPname(),product.getMarket_price(),                                            product.getShop_price(),product.getPimage(),product.getPdate(),product.getIs_hot(),                                            product.getPdesc(),product.getPflag(),product.getCid());                          }

3 删除

分析:你要确定你要删除的是那个,所以你要传参数,来确定你删除的是那个

Pid 来确定

Jsp

                                                                                                                                                                                                                                                                                                                                                                                                              

 

 

JS

  

function delProduct(pid){                                   var isDel = confirm("您确认要删除吗?");                                   if(isDel){                                            //要删除                                            location.href = "${pageContext.request.contextPath}/adminDelProduct?pid="+pid;                                   }                          }

 

 

4 修改

 

比较不好处理的点:商品的分类select 里面的option

1在编辑商品时需要向数据库传递你要更改的那个

2 Select里面的option默认显示是那个;

 需要option里面的value和category里面的cid进行对比(js或者jq)

 

 

Jsp里面的编辑代码

                                                                                                                                                                                                                             

 

 5 源代码

源代码:链接:https://pan.baidu.com/s/1J5u4s3emjlluZIWw7TkZmw 密码:cl9b

 

转载于:https://www.cnblogs.com/liu-wang/p/8612348.html

你可能感兴趣的文章
HTTP - 持久连接
查看>>
添加路由时啥时候是dev啥时候是gw
查看>>
redis 中文字符显示
查看>>
登录日志分析常用查询
查看>>
Codeforces Round #228 (Div. 1) 388B Fox and Minimal path
查看>>
【nosql实现企业网站系列之一】mongodb的安装
查看>>
短信服务供应商价格总览
查看>>
获取本机IP(考虑多块网卡、虚拟机等复杂情况)
查看>>
笔记之_java整理ORM框架
查看>>
CentOS下安装python3.x版本
查看>>
CAP定理(原则)以及BASE理论
查看>>
「玩转树莓派」搭建属于自己的云盘服务
查看>>
有道语料库爬虫
查看>>
VS2019 实用设置
查看>>
for循环语句之求和,阶乘,求偶,求n次篮球蹦起高度
查看>>
CFileDialog
查看>>
[转载]EXTJS学习
查看>>
SQL Server2012完全备份、差异备份、事务日志备份和还原操作
查看>>
Flash动画播放
查看>>
springmvc+mybatis+dubbo+zookeeper 分布式架构
查看>>